package com.xunjing.log.controller;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xunjing.common.core.web.domain.MyBaseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xunjing.common.log.annotation.Log;
import com.xunjing.common.log.enums.BusinessType;
import com.xunjing.common.security.annotation.RequiresPermissions;
import com.xunjing.log.domain.IcPayLog;
import com.xunjing.log.service.IIcPayLogService;
import com.xunjing.common.core.web.controller.BaseController;
import com.xunjing.common.core.web.domain.AjaxResult;
import com.xunjing.common.core.utils.poi.ExcelUtil;
import com.xunjing.common.core.web.page.TableDataInfo;

/**
 * 银行支付日志Controller
 *
 * @author zhangyt
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/log")
public class IcPayLogController extends BaseController {
    @Autowired
    private IIcPayLogService icPayLogService;

    /**
     * 查询银行支付日志列表
     */
    @RequiresPermissions("log:log:list")
    @GetMapping("/list")
    public TableDataInfo list(IcPayLog icPayLog) {
        startPage();
        LambdaQueryWrapper<IcPayLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.ge(MyBaseEntity::getCreateTime,LocalDateTime.now().plusMonths(-2));
        wrapper.le(MyBaseEntity::getCreateTime,LocalDateTime.now());
        List<IcPayLog> list = icPayLogService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出银行支付日志列表
     */
    @RequiresPermissions("log:log:export")
    @Log(title = "银行支付日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IcPayLog icPayLog) {
        List<IcPayLog> list = icPayLogService.selectIcPayLogList(icPayLog);
        ExcelUtil<IcPayLog> util = new ExcelUtil<IcPayLog>(IcPayLog.class);
        util.exportExcel(response, list, "银行支付日志数据");
    }

    /**
     * 获取银行支付日志详细信息
     */
    @RequiresPermissions("log:log:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(icPayLogService.getById(id));
    }

    /**
     * 新增银行支付日志
     */
    @RequiresPermissions("log:log:add")
    @Log(title = "银行支付日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IcPayLog icPayLog) {
        icPayLog.setFlag("N");
        icPayLog.setCreateBy("sd");
        icPayLog.setUpdateBy("sd");
        icPayLog.setRemark("sdsd");
        icPayLog.setCreateTime(LocalDateTime.now());
        return toAjax(icPayLogService.save(icPayLog));
    }

    /**
     * 修改银行支付日志
     */
    @RequiresPermissions("log:log:edit")
    @Log(title = "银行支付日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IcPayLog icPayLog) {
        return toAjax(icPayLogService.updateById(icPayLog));
    }

    /**
     * 删除银行支付日志
     */
    @RequiresPermissions("log:log:remove")
    @Log(title = "银行支付日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(icPayLogService.removeByIds(Arrays.asList(ids)));
    }
}
